#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;

void InsertSort(int* a, int n)
{
	for (int i = 1; i < n; i++)
	{
		int end = i - 1;
		int tmp = a[i];
		while (end >= 0)
		{
			if (tmp < a[end])
			{
				a[end + 1] = a[end];
				--end;
			}
			else
			{
				break;
			}
		}

		a[end + 1] = tmp;
		for (int i = 0; i < n; i++)
		{
			cout << a[i];
			if (i < n - 1)
			{
				cout << ' ';
			}
		}
		cout << endl;
	}

}

int BubbleSort(int* a, int n)
{
	int ex = 0;
	for (int j = 0; j < n; j++)
	{
		for (int i = 1; i < n - j; i++)
		{
			if (a[i - 1] > a[i])
			{
				swap(a[i - 1], a[i]);
				ex++;
			}
		}
	}
	return ex;
}

void test4()
{
	int n;
	while (cin >> n)
	{
		int* a = new int[n];
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		InsertSort(a, n);
	}
	cout << endl;
}

void test5()
{
	int n;
	while (cin >> n)
	{
		int* a = new int[n];
		for (int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		cout << BubbleSort(a, n) << endl;
	}
	cout << endl;
}

int main()
{
	test5();
	return 0;
}